package test00.test04;

import java.util.*;

/**
 * @Author lzp
 * @Date 2024-04-09
 */
public class Studunt {
    private String name;
    private int age;

    public Studunt(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return name + "-" + age;
    }

    public static void main(String[] args) {
        List<Studunt> studunts = new ArrayList<>();
        studunts.add(new Studunt("张三",10));
        studunts.add(new Studunt("李四",11));
        studunts.add(new Studunt("王五",12));
        studunts.add(new Studunt("赵六",13));


        //对集合进行排序的方法
        Collections.sort(studunts,(Studunt a,Studunt b) -> b.age - a.age);
        for (Studunt studunt : studunts) {
            System.out.println(studunt);
        }
    }
}
